<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
  <title>修改班级</title>
  <link rel="icon" href="favicon.ico" type="${pageContext.request.contextPath}/assert/image/ico">
  <link href="${pageContext.request.contextPath}/assert/css/bootstrap.min.css" rel="stylesheet">
  <link href="${pageContext.request.contextPath}/assert/css/materialdesignicons.min.css" rel="stylesheet">
  <link href="${pageContext.request.contextPath}/assert/css/style.min.css" rel="stylesheet">
  <!--日期选择插件-->
  <link rel="stylesheet" href="${pageContext.request.contextPath}/assert/js/bootstrap-datepicker/bootstrap-datepicker3.min.css">
</head>
<body>
<div class="lyear-layout-web">
  <div class="lyear-layout-container">
    <%--抽取公共部分进行封装起来，增加代码的复用性，减少代码的冗余！--%>
    <jsp:include page="_aside_header.jsp"></jsp:include>
    <!--页面主要内容-->
    <main class="lyear-layout-content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-md-12">
            <div class="card">
              <div class="card-body">
                <form  id="myform"   action="${pageContext.request.contextPath}/student?r=edit" method="post">
                  <div class="form-group">
                    <label>学号</label>
                    <input  required class="form-control" type="text" name="sno"  value=${entity.sno}>
                  </div>
                  <div class="form-group">
                    <label>密码</label>
                    <input  required class="form-control" type="text" name="password"  value=${entity.password}>
                  </div>
                  <div class="form-group">
                    <label>名字</label>
                    <input  required class="form-control" type="text" name="name"  value="${entity.name}">
                  </div>
                  <div class="form-group">
                    <label>电话</label>
                    <input   class="form-control" type="text" name="tele"  value=${entity.tele}>
                  </div>
                  <div class="form-group">
                    <label>入学时间</label>
                    <input class="form-control js-datepicker m-b-10" type="text"
                           name="enterDate"  value=${entity.enterDate} data-date-format="yyyy-mm-dd" />
                  </div>
                  <div class="form-group">
                    <label>年龄</label>
                    <input class="form-control" type="number"  name="age" value=${entity.age}>
                  </div>
                  <div class="form-group">
                    <label>性别</label>
                    <select class="form-control"  name="gender" size="1">
                      <option value="">请选择</option>
                      <option <c:if test="${entity.gender == 'm'}">selected</c:if> value="m">男</option>
                      <option <c:if test="${entity.gender == 'w'}">selected</c:if> value="w">女</option>
                    </select>
                  </div>
                  <div class="form-group">
                    <label>地址</label>
                    <textarea class="form-control" name="address">${entity.address}</textarea>
                  </div>
                  <div class="form-group">
                    <label>班级</label>
                    <input class="form-control" type="text" value=${entity.clazzNO} name="clazzNO">
                    <%--<select class="form-control"  name="clazzNO" size="1">
                      <option value="">请选择</option>
                      <c:forEach items="${cs}" var="a" varStatus="s">
                        <option value="${a.clazzNo}">${a.clazzNo}/${a.name}</option>
                      </c:forEach>
                    </select>--%>
                  </div>
                  <div class="form-group">
                    <button class="btn btn-primary" type="submit">提交</button>
                  </div>
                </form>
              </div>
            </div>
          </div>
        </div>
      </div>
    </main>
    <!--End 页面主要内容-->
  </div>
</div>

<jsp:include page="_js.jsp"></jsp:include>
<script type="text/javascript">
  $(document).ready(function (e){
    $("#myform").submit(function (event){
      //因为表单的submit本身就有提交功能，但是现在要使用ajax进行请求，所以要关闭原来的表单提交
      event.preventDefault();
      lightyear.loading('show');//显示加载
      // 假设ajax提交操作
      //进行表单数据的序列化
      var formData = $(this).serialize();
      console.log(formData)
      $.ajax({
        type:"post",
        url:$(this).attr("action"),
        data:formData,
        dataType:"json",
        success:function (data){
          if(data.success){
            lightyear.loading('hide');
            lightyear.url('${pageContext.request.contextPath}/student');
            lightyear.notify(data.msg, 'success', 500);
          }else {
            lightyear.loading('hide');
            lightyear.notify(data.msg, 'danger', 3000);
          }
        },
        error:function (){
          lightyear.loading('hide');
          lightyear.notify("请求失败请检查！", 'danger', 3000);
        }
      })})


  })

</script>
</body>
</html>